import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import basicSsl from '@vitejs/plugin-basic-ssl'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
import postCssPxToRem from 'postcss-pxtorem'
import { VantResolver } from 'unplugin-vue-components/resolvers'
const Timestamp = new Date().getTime() //随机时间戳

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    // basicSsl() // https
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver(), VantResolver()]
    }),
    ElementPlus({
      useSource: true
    })
  ],
  css: {
    postcss: {
      plugins: [
        // postCssPxToRem({
        //   rootValue: 192, // 设计稿尺寸 1rem大小
        //   propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        // })
      ]
    }
  },
  resolve: {
    alias: {
      '@': resolve('src'),
      'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
    }
  },
  server: {
    host: '0.0.0.0'
    // port: 3000,
    // proxy: {
    //   '/api': {
    //     target: 'http://127.0.0.1:3001',
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, '')
    //   }
    // }
  },
  // 打包配置
  base: '', // 静态资源基础路径
  build: {
    sourcemap: false, // 输出.map文件,默认是false
    rollupOptions: {
      output: {
        chunkFileNames: `static/js/[name].[hash].${Timestamp}.js`,
        entryFileNames: `static/js/[name].[hash].${Timestamp}.js`,
        assetFileNames: `static/[ext]/[name].[hash].${Timestamp}.[ext]`
      }
    }
  }
})
